package android.slc.box.commonlibrary;

import android.slc.box.commonlibrary.compat.SlcResourceUtils;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * slc
 */
public class ToastUtils {
    private static Stage stage = new Stage();
    private static Label label = new Label();

    static {
        stage.initStyle(StageStyle.TRANSPARENT);//舞台透明
    }

    //默认3秒
    public static void showLong(String msg) {
        toast(msg, 3000);
    }

    //默认2秒
    public static void showShort(String msg) {
        toast(msg, 2000);
    }

    //默认3秒
    public static void showLongRes(String msg) {
        toast(SlcResourceUtils.getString(msg), 3000);
    }

    //默认2秒
    public static void showShortRes(String msg) {
        toast(SlcResourceUtils.getString(msg), 2000);
    }

    /**
     * 指定时间消失
     *
     * @param msg
     * @param time
     */
    public static void toast(String msg, long time) {
        /*label.setText(msg);
        Single.timer(time, TimeUnit.MILLISECONDS)
                .compose(SlcRxJavaUtils.applyOsAndroidSchedulers())
                .subscribe(new SimpleSingleObserver<Long>() {
                    @Override
                    public void onSuccess(Long delay) {
                        super.onSuccess(delay);
                        stage.close();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                });
        init(msg);
        stage.show();*/
    }

    //设置消息
    private static void init(String msg) {
        Label label = new Label(msg);//默认信息
        label.setTextFill(Color.rgb(225, 255, 226));//消息字体颜色
        label.setPadding(new Insets(16));
        label.setAlignment(Pos.CENTER);//居中
        label.setFont(new Font(18));//字体大小
        // 透明,圆角
        label.setStyle("-fx-background: rgba(56,56,56,0.6);-fx-border-radius: 50;-fx-background-radius: 50");//label
        Scene scene = new Scene(label);
        scene.setFill(null);//场景透明
        stage.setScene(scene);
    }
}
